package peppa.george.org.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import peppa.george.base.Util.AjaxResult;
import peppa.george.org.domain.User;
import peppa.george.org.Service.LoginService;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    LoginService loginService;

    @GetMapping
    public AjaxResult login(String username, Long password, HttpServletRequest request){
        System.out.println(username+"==="+password);
        User user = loginService.login(username,password);
        if (user!=null){
            request.getSession().setAttribute("user",user);
            return AjaxResult.me().success();
        }
        return  AjaxResult.me().fail();
    }
    @GetMapping("hello")
    public String hello(){
        return "hello1";
    }
}
